package action;

import java.sql.Connection;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import data.ConnectionProvider;

public abstract class ConnectionAwareAction extends Action {
	private static final Logger logger = Logger.getLogger(ConnectionAwareAction.class);
	private static final String CONNECTIONAWAREACTION_INFO = "ConnectionAwareAction is error"; 
	private static final String CONNECTIONAWAREACTION_IGNORE = "ConnectionAwareAction is ignore"; 
	
	protected Connection getConnection() {
		try {
			return ConnectionProvider.getConnection();
		} catch (Exception  e) {
			logger.error(ConnectionAwareAction.CONNECTIONAWAREACTION_INFO + e.getMessage());
			return null;
		}
	}

	protected void closeConnection(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			} catch (Exception ignore) {
				logger.error(ConnectionAwareAction.CONNECTIONAWAREACTION_IGNORE + ignore.getMessage());
			}
		}
	}

	protected void handleInvalidConnection(Throwable e) {

	}

	protected void handleException(Throwable e) {

	}
}
